package com.gagakuai.demo.refrence;

import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor;
import org.springframework.stereotype.Component;

/*
 * @program: settement
 * @description:
 * @author: houhong
 * @create: 2022-11-12 20:05
 */
@Component
public class MethodBeforeInterceptor2 implements SmartInstantiationAwareBeanPostProcessor {
    @Override
    public Object getEarlyBeanReference(Object bean, String beanName) throws BeansException {
        if ("serviceA".equals(beanName) || "servicea".equals(beanName)) {

            ProxyFactory proxyFactory = new ProxyFactory(bean);
            proxyFactory.addAdvice((MethodBeforeAdvice) (method, objects, o) -> {
                System.out.println("你好,service1");
            });
            return proxyFactory.getProxy();
        }

        return bean;
    }
}